<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$setting.webname} - 发送消息</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/public/static/admin/layui/css/layui.css" rel="stylesheet">
    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        #demo2 img{
            height: 110px;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>发送消息</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{:url('Admins/admin')}">主页</a>
                </li>
                <li>
                    <strong>发送消息</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑信息</h5>
                    </div>

                    <div class="ibox-content">
                        <div class="page-container">
                            <!-- 输入信息开始 -->
                            <h5>编辑信息：</h5>
                            <textarea id="message" name="comment" class="form-control" required="" aria-required="true"></textarea>
                            <!-- 输入信息结束 -->
                            <!-- 上传图片开始 -->
                            <h5>上传图片：</h5>
                            <div class="layui-upload">
                                <button type="button" class="btn btn-info" id="test2">添加图片</button>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="demo2"></div>
                                </blockquote>
                            </div>
                            <!-- 上传图片 -->
                            <!-- 选择设备开始 -->
                            <h5>选择设备</h5>
                            <div class="col-sm-12">
                               {foreach $list as $vo}
                                    <div class="col-sm-4">
                                        {if condition="$vo.status == 1"}
                                            <i class="fa fa-circle" style="color:green"></i>&nbsp;
                                            <i class="fa fa-check-square-o check" data-id="{$vo.id}"></i>
                                        {else /}
                                            <i class="fa fa-circle-o"></i>&nbsp;
                                            <i class="fa fa-square-o" data-id="{$vo.id}"></i>
                                        {/if}
                                        <span class="m-l-xs">{$vo.name}</span>
                                        <span class="m-l-xs">{$vo.desc}</span>
                                    </div>
                                {/foreach}
                            </div>
                            <!-- 选择设备结束 -->
                            <!-- 发送按钮开始 -->
                            <div class="col-sm-2" style="margin-top:20px;">
                                <button type="button" class="btn btn-info btn-sm btn-block" id="save"><i class="fa fa-cloud-upload"></i> 发送</button>
                            </div>
                            <!-- 发送按钮 -->
                            <div style="clear:both"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </div>
    <!-- 全局js -->
    <script src="/public/static/admin/layui/layui.js"></script>
    <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="/public/static/admin/js/content.js?v=1.0.0"></script>

    <script src="/public/static/admin/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script>
        layui.use('upload', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
            var photo = "";
            $("#save").click(function(){
                var ss = $(".fa-check-square-o").length;
                var device = "";
                for(i=0;i<ss;i++){
                    device += $(".fa-check-square-o").eq(i).attr("data-id")+",";
                }
                //多图片上传
                $.post("{:url('Messages/addMessage')}",{message:$("#message").val(),photo:photo,device:device},function(data){
                    top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
                        if(data.url){
                            window.location.href = data.url;
                        }
                    });
                });
            });

            upload.render({
                elem: '#test2'
                ,url: "{:url('Messages/upload')}"
                ,multiple: true
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                    });
                }
                ,done: function(res){
                    //上传完毕
                    //如果上传失败
                    if (res.code == 404) {
                        return layer.msg(res.msg);
                    }
                    //上传成功
                    if (res.code == 1) {
                        photo += res.photo+",";
                    }
                }
            });

        });

      $(".check").click(function(){
            if($(this).attr('class') == "fa fa-square-o check"){
                $(this).attr('class',"fa fa-check-square-o check");
            }else{
                $(this).attr('class',"fa fa-square-o check");
            }
      });
    </script>

  </body>
</html>
